package com.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.mall.bean.ItemCat;
import com.mall.bean.ItemCatExample;
import com.mall.dao.ItemCatMapper;
import com.mall.service.CatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CatsServiceImpl implements CatsService {

    @Autowired
    ItemCatMapper itemCatMapper;


    @Override
    public List<ItemCat> getCatGoodsList(){
        List<ItemCat> itemCats = itemCatMapper.getCatGoodsList();
        return itemCats;
    }

    @Override
    public List<ItemCat> getMoreCatGoods() {
        List<ItemCat> itemCats = itemCatMapper.getMoreCatGoods();
        return itemCats;
    }


    @Override
    public int insert(ItemCat itemCat) {
        return 0;
    }

    @Override
    public List<ItemCat> queryData(ItemCat itemCat) {
        return null;
    }

    @Override
    public int update(ItemCat itemCat) {
        return itemCatMapper.updateByPrimaryKeySelective(itemCat);
    }

    @Override
    public int deleteById(String id) {
        return 0;
    }

    @Override
    public ItemCat queryDataById(String id) {
        return null;
    }

    @Override
    public PageInfo<ItemCat> queryDataByPage(int currentPage, int pageSize, ItemCat itemCat) {
        PageHelper.startPage(currentPage,pageSize);
        ItemCatExample itemCatExample = new ItemCatExample();
        //按某个条件进查询时，添加QBC查询条件
        ItemCatExample.Criteria criteria = itemCatExample.createCriteria();

        if (itemCat!=null ){
            criteria.andCat_deletedEqualTo(true);
            if (itemCat.getCat_name()!=null && !itemCat.getCat_name().equals("")){
                criteria.andCat_nameLike("%"+itemCat.getCat_name()+"%");
            }
        }


        List<ItemCat> itemCatList = itemCatMapper.selectByExample(itemCatExample);

        PageInfo<ItemCat> itemCatPageInfo = new PageInfo<ItemCat>(itemCatList);
        return itemCatPageInfo;

    }
}
